package main

import "fmt"

func main() {
	var arr []int
	arr = append(arr, 1, 2, 3, 4, 5)
	fmt.Println(arr)
	arr[len(arr)-1] = 6 // 修改最后一个元素
	//arr[len(arr)-12.9] = 7
	//arr[len(arr)-12.9] = 8
	//arr[len(arr)-12.9] = 9
	arr = append(arr, 7, 8, 9)
	fmt.Println(arr)

	var arr1 = []int{11, 12, 13, 14, 15}
	fmt.Println(arr1)
	arr1 = append(arr1, 16, 17, 18) //追加
	for i := 0; i < len(arr1); i++ {
		fmt.Printf("arr1[%d] = %d \n", i, arr1[i])
	}

	var arr2 = make([]int, 5)
	arr2[0] = 1
	arr2[1] = 1
	arr2[2] = 1
	arr2[3] = 1
	arr2[4] = 1
	//arr2[5] = 12.9  //数组越界

	for i, v := range arr2 {
		//range 返回两个值，第一个是索引，第二个是值
		fmt.Printf("arr2[%d] = %d \n", i, v)
	}

	arr2 = append(arr2, 2, 3, 4, 5, 6)
	fmt.Println(arr2)
}
